import type { CascaderOption, UploadRawFile } from 'element-plus'
import type { Fn } from '@vueuse/core'

// 文件
export declare interface BusinessUIFile {
  id: string
  fileName: string
  createdOn?: string
  createdOnString?: string
  dirPath?: string
  fileEx?: string
  fkId?: string
  imgThumbnailPath?: string
  modifiedOn?: string
  modifiedOnString?: string
  path?: string
  uploadUser?: string
  raw?: UploadRawFile
  uid?: number
  url?: string
  uploadUserName?: string
  idx?: number
}

// 按钮权限
export declare interface BusinessUIAction {
  action: string
  api: string
  component: string
  global: boolean
  idx: number
  method: string
  name: string
  visible: boolean
  type: string
  default_value: string
  default_value_parse: TypedAny
  set_json: string
  set_json_parse: TypedAny
  model?: string
  business_id?: string
  description?: string
  defaultValue?: boolean
  confirm?: boolean
}

// 表单组件
export declare interface FormComponentType {
  title?: string
  label: string
  value: string
  document: string
  type?: string
  props: TypedAny
  col: TypedAny
  elComponent?: string
  children: FormComponentType[]
  server?: {
    api: string
    method: string
    pid?: string
    params?: TypedAny
    data?: string
    sort?: string
    value: string
    label: string
  }
  keys?: string[]
  suffix?: string[]
  field?: string
  options?: SelectOptionType[]
  hide?: boolean
  show?: string[]
}

// 表单传参
export declare interface FormComponentProp {
  label: string
  value: string
  type: string
  default_value?: string
  values?: { title: string; values: string[] }[]
}

// 表格列
export declare interface TableColumnCustom {
  id?: string
  field: string
  title: string
}

// 自定义表格
export declare interface TableFormColumn {
  label?: string
  type?: string
  prop?: string
  showOverflowTooltip?: boolean
  width?: string | number
  minWidth?: string | number
}

// 自定义表格-表单
export declare interface TableFormSelectOption {
  value: string | number
  label: string
  children?: FormColumn[]
}

// 自定义表格-表单列
export declare interface FormColumn {
  type: string
  prop: string
  label?: string
  multiple?: boolean
  options?: TableFormSelectOption[]
}

// 服务器列
export declare interface IFListColumnType extends TableColumnCustom {
  name: string
  data_type: string
  col?: TypedAny
  component?: string
}

// 表格列
export declare interface BusinessUIColumnType extends TableColumnCustom {
  field: string
  title: string
  set_json: string
  set_json_parse: {
    props: TypedAny
    component?: string
    nodeApp?: boolean
    showFooter?: boolean
    isTips?: boolean
    formatType?: string
    expandAll?: boolean
    formatFixed?: number
    prefix?: string
    suffix?: string
    merge?: boolean
  }
  is_pid: boolean
  is_sort_col: boolean
  orderby?: 'asc' | 'desc' | null
  visible?: boolean
  customer: {
    actions: string[]
  }
  params?: BusinessUIColumnType | any
  children?: BusinessUIColumnType[]
  seq?: number
  treeNode?: boolean
}

/**
 * 表格请求返回头部
 */
export declare interface BusinessTabHead {
  column_data: string
  column_id: string
  column_name: string[]
  id: string
  idx: number
  name: string
  p_id: string
}

// 查询列
export declare interface BusinessUIQueryColumnType {
  visible: boolean
  required: boolean
  field: string
  rel_item?: string
  title: string
  component: string
  elComponent?: string
  type?: string
  idx: number
  set_json: string
  set_json_parse: {
    linkage?: string[]
    url?: string
    method?: string
    convert?: TypedAny
    props: TypedAny
    col: TypedAny
    description?: string
    formatType?: string
    formatFixed?: number
  }
  business_id?: string
  default_value: string
  default_value_parse: TypedAny
  expand?: boolean
  linkage?: boolean
  is_api?: boolean
  description?: string
  disable_on_edit?: boolean
  options?: SelectOptionType[]
  hide?: boolean
}

// 运行详情
export declare interface RuningType {
  approvalUsers: string
  approvalUsersId: string
  approvedUsersId: string
  createdOn: string
  createdOnString: string
  detail: string
  endDate: string
  endDateString: string
  errText: string
  flag: string
  id: string
  instanceId: string
  instanceName: string
  isFinish: boolean
  modifiedOn: string
  modifiedOnString: string
  nodeId: string
  remark: string
  runingMinute: number
  status: number
  statusString: string
  submitUser: string
  submitUserId: string
  ver: string
  workFlowDesignId: string
}

/**
 * 运行列表
 */
export declare interface RuningDetail {
  approvalAccess?: number
  approvalType?: number
  approvalTypeString?: string
  approvalUser?: string
  approvalUserId?: string
  createdOn?: string
  createdOnString?: string
  id: string
  modifiedOn?: string
  modifiedOnString?: string
  nodeId: string
  nodeLabel?: string
  nodeType?: number
  remark?: string
  seq?: number
  workFlowRuningId?: string
  label?: string
  props?: TypedAny
  status?: string
  submitUser?: string
  nodeName?: string
}

// 流程row
export declare type WorkflowDesignRow = {
  edges: WorkflowDesignEdge[]
  id: string
  name: string
  nodes: WorkflowDesignNode[]
  ver?: string
  flag?: string
  ins_name?: string
  descript?: string
  created_on?: string
  instanceName?: string
  uiFormItems?: BusinessUIQueryColumnType[]
}

// 流程图
export declare interface WorkFlowDesignInfoRunning {
  approvals: TypedAny[]
  design: WorkflowDesignRow
  details: RuningDetail[]
  node: WorkflowDesignNode
  path: TypedAny[]
  runing: RuningType
  statusString: string
  status: number
}

// 流程运行详情
export declare interface WorkFlowDesignInfo {
  business: RouteItems
  dic_table: DicType[]
  runing: WorkFlowDesignInfoRunning
  ui_form: BusinessUIFormType
  wfRuning: IsWorkFlowDesign
  can_edit_items: string[]
}

// 流程图按钮权限
export declare interface IsWorkFlowDesign {
  can_approval: boolean
  can_submit: boolean
  can_un_approval: boolean
  can_un_submit: boolean
  can_set_status: boolean
}

// 查询栏
export declare interface BusinessUIQueryType {
  id: string
  api: string
  align?: string
  method: string
  type_name: string
  default_value: string
  default_value_parse: TypedAny
  items: BusinessUIQueryColumnType[]
}

// 表单
export declare interface BusinessUIFormType {
  id: string
  api: string
  align?: string
  method: string
  type_name: string
  default_value: string
  default_value_parse: TypedAny
  items: BusinessUIQueryColumnType[]
}

// 表格
export declare interface BusinessUITableType {
  id: string
  api: string
  align?: string
  method: string
  type_name: string
  default_value: string
  default_value_parse: {
    toolbarConfig: {
      enabled?: boolean
      perfect?: boolean
      refresh?: boolean
      custom?: boolean
      export?: boolean
      print?: boolean
      zoom?: boolean
    }
    keyField?: string
    renderMethod?: 'editRender' | 'cellRender'
    emptyText?: string
    height?: number
  }
  columns: BusinessUIColumnType[]
  edit_render?: boolean
  querys?: TypedAny[]
  pagination?: boolean
  children?: CustomGridGroupType[]
}

// 表格组配置
export declare interface CustomGridGroupType {
  id: string
  title?: string
  height?: number
  business_id: string
  default_value: string
  default_value_parse: TypedAny
}

// 字典
export declare interface DicType {
  column_name: string
  value_text: string
  display_text: string
  sort: number
  type_name?: string
  display_type?: string
}

export declare interface IFListType {
  column: IFListColumnType[]
  name: string
  type_name: string
}

export declare interface TemplateUIType {
  actions: BusinessUIAction[]
  dic_query?: DicType[]
  dic_table?: DicType[]
  ui_form?: BusinessUIFormType
  ui_query?: BusinessUIQueryType
  ui_table?: BusinessUITableType
  wf_design?: WorkflowDesignRow
}

export declare interface TableFormPagination {
  page: number
  pageSize: number
}

// 部门
export declare interface DepType extends CascaderOption {
  created_on: string
  id: string
  name: string
  pid: string
  sort: string
  user_count: string
  value: string
  label: string
  children?: DepType[]
}

// 部门
export declare interface SubType extends CascaderOption {
  id: string
  name: string
  sort: number
  sequence: string
  created_on: string
  value: string
  label: string
  children?: DepType[]
}

// 全局表单参数
export declare interface BaseFormRow {
  onFetch: Fn
  row?: TypedAny
  uiForm?: BusinessUIFormType
  uiTable?: BusinessUITableType
  dicTable?: DicType[]
  action?: BusinessUIAction
  isForm?: boolean
  list?: string[]
  running_id?: string
}

// 多级表头
export declare interface TabHeadType extends BusinessUIColumnType {
  column_change: string
  column_data: string
  column_id: string
  column_name: string[]
  id: string
  idx: number
  name: string
  p_id: string
  children: TabHeadType[]
  width?: string | number
}
